﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FinanceAdviser.Data;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace FinanceAdviser.VariableTemplate
{
    public class VariableTiles : DataTemplateSelector
    {

        public DataTemplate RedTemplate { get; set; }
        public DataTemplate GreenTemplate { get; set; }
        public DataTemplate WhiteTemplate { get; set; }
        public DataTemplate NormalTemplate { get; set; }
        public DataTemplate FixedDepositTemplate { get; set; }
        

        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;

            if (element != null && item != null)
            {

                if (item.GetType() == typeof(SampleDataItem))
                {

                    if ((item as SampleDataItem).UniqueId.StartsWith("Red"))
                        return RedTemplate;
                    if ((item as SampleDataItem).UniqueId.StartsWith("Green"))
                        return GreenTemplate;
                    if ((item as SampleDataItem).UniqueId.StartsWith("White"))
                        return WhiteTemplate;
                    if ((item as SampleDataItem).UniqueId.StartsWith("Normal"))
                        return NormalTemplate;
                    if ((item as SampleDataItem).UniqueId.StartsWith("FixedDeposit"))
                        return FixedDepositTemplate;

                }
                else if (item.GetType() == typeof(GroupDataItem))
                {
                    if ((item as GroupDataItem).UniqueId.StartsWith("Red"))
                        return RedTemplate;
                    if ((item as GroupDataItem).UniqueId.StartsWith("Green"))
                        return GreenTemplate;
                    if ((item as GroupDataItem).UniqueId.StartsWith("White"))
                        return WhiteTemplate;
                    if ((item as GroupDataItem).UniqueId.StartsWith("Normal"))
                        return NormalTemplate;
                    if ((item as GroupDataItem).UniqueId.StartsWith("FixedDeposit"))
                        return FixedDepositTemplate;
                }
            }
            return base.SelectTemplateCore(item, container);
        }

    }
}
